Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add logging to explain reasons for Comet not being able to run a query stage natively #397

Merged
merged 15 commits into from
May 14, 2024

Conversation

andygrove
Copy link
Member

Which issue does this PR close?

Closes #385

Rationale for this change

As a user, I would like to understand why my query stages are not running natively.

What changes are included in this PR?

New config + logging

How are these changes tested?

Tested manually:

scala> spark.read.parquet("/tmp/test").createOrReplaceTempView("t1")
24/05/07 10:55:16 INFO src/lib.rs: Comet native library initialized
24/05/07 10:55:16 WARN CometSparkSessionExtensions$CometExecRule: Comet cannot execute this plan natively because Execute CreateViewCommand is not supported

scala> spark.sql("select * from t1 where cast(cast(a as double) as decimal(10,2)) > 5").show
24/05/07 10:55:29 WARN CometSparkSessionExtensions$CometExecRule: Comet cannot execute this plan natively because:
	- Comet does not guarantee correct results for cast from DoubleType to DecimalType(10,2) with timezone Some(America/Denver) and evalMode LEGACY (No overflow check). To enable all incompatible casts, set spark.comet.cast.allowIncompatible=true
	- CollectLimit is not supported
+---+
|  a|
+---+
|  9|
|  8|
|  6|
|  7|
+---+

@andygrove andygrove marked this pull request as draft May 7, 2024 18:27
@andygrove andygrove marked this pull request as ready for review May 7, 2024 19:00
@andygrove andygrove requested a review from viirya May 7, 2024 19:01
@andygrove
Copy link
Member Author

@parthchandra How does this look?

Copy link
Contributor

@parthchandra parthchandra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just some observations.

@@ -276,6 +276,14 @@ object CometConf {
.booleanConf
.createWithDefault(false)

val COMET_EXPLAIN_FALLBACK_ENABLED: ConfigEntry[Boolean] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to make this configurable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a config should be good. Sometimes it might be verbose.

@@ -734,6 +734,22 @@ class CometSparkSessionExtensions
} else {
var newPlan = transform(plan)

// if the plan cannot be run natively then explain why (when appropriate config is enabled)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that ExecRule is going to be invoked multiple times as planning proceeds, this may get logged multiple times for the same plan. Perhaps that is why we need to keep this configurable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is one reason, yes. The logging could get verbose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume that this feature is useful in development but less so in production since we have the integration with Spark's explain for that.

@@ -734,6 +734,22 @@ class CometSparkSessionExtensions
} else {
var newPlan = transform(plan)

// if the plan cannot be run natively then explain why (when appropriate config is enabled)
if (CometConf.COMET_EXPLAIN_FALLBACK_ENABLED.get() && !isCometNative(newPlan)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comet could only trigger native execution for partial query plan. This check isCometNative(newPlan) only applies for the top operator.

@andygrove andygrove marked this pull request as draft May 8, 2024 20:20
@andygrove
Copy link
Member Author

I am moving this to draft for now while I test with TPC-H queries and make some improvements

@andygrove andygrove marked this pull request as ready for review May 13, 2024 13:11
@andygrove
Copy link
Member Author

@viirya @parthchandra This PR is ready for another review. I simplified the logic and removed the check to see if the top level operator is native or not. Instead, if we have recorded any info using withInfo then that info will be displayed when the config is enabled. There is an example in the documentation as part of this PR.

// if the plan cannot be run fully natively then explain why (when appropriate
// config is enabled)
if (CometConf.COMET_EXPLAIN_FALLBACK_ENABLED.get()) {
new ExtendedExplainInfo().extensionInfo(newPlan) match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but I feel ExtendedExplainInfo can be object

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had the same thought

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that it has to be a class due to the way this integrates into Spark, but I am not sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just seeing this. I don't think Spark prevents us from this being an object. I'll take care of this. #452

@@ -45,7 +45,7 @@ class ExtendedExplainInfo extends ExtendedExplainGenerator {
}
}

private def extensionInfo(node: TreeNode[_]): Set[String] = {
def extensionInfo(node: TreeNode[_]): Set[String] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps private[comet] instead of public?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I made that change.

@andygrove
Copy link
Member Author

@viirya I have 2 approvals but need a committer approval to be able to merge.

@viirya
Copy link
Member

viirya commented May 13, 2024

Looks good to me. Thanks @andygrove

@andygrove andygrove merged commit 3808306 into apache:main May 14, 2024
40 checks passed
@andygrove andygrove deleted the explain-fallback-reasons branch May 14, 2024 04:10
himadripal pushed a commit to himadripal/datafusion-comet that referenced this pull request Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow user to see reasons why query stage cannot be run natively
4 participants